<?php
class NewsModel extends Model {

	protected $tableName = 'news';
	protected $fields = array(
			0=>'nid',
			1=>'title',
			2=>'profile',
			3=>'content',
			4=>'pic',
			5=>'ctime',
			6=>"tid",
			7=>"is_display"
			
	);

	public function getNewsList($limit = 20, $map = array(),$order = "nid DESC"){
		// 添加用户表的查询，用于关联查询
		
		if (isset ( $_POST )) {
			$_POST ['nid'] && $map ['nid'] = intval ( $_POST ['nid'] );
			//$_POST ['title'] && $map ['title'] = t ( $_POST ['title'] );
			//$_POST ['profile'] && $map ['profile'] = t ( $_POST ['profile'] );
			//$_POST ['content'] && $map ['content'] = t ( $_POST ['content'] );
			$_POST ['pic'] && $map ['pic'] = t ( $_POST ['pic'] );
			$_POST ['tid'] && $map ['tid'] = t ( $_POST ['tid'] );
		
			// 注册时间判断，apply_time为数组格式
			if (! empty ( $_POST ['ctime'] )) {
				if (! empty ( $_POST ['ctime'] [0] ) && ! empty ( $_POST ['ctime'] [1] )) {
					// 时间区间条件
					$map ['ctime'] = array (
							'BETWEEN',
							array (
									strtotime ( $_POST ['ctime'] [0] ),
									strtotime ( $_POST ['ctime'] [1] )
							)
					);
				} else if (! empty ( $_POST ['ctime'] [0] )) {
					// 时间大于条件
					$map ['ctime'] = array (
							'GT',
							strtotime ( $_POST ['ctime'] [0] )
					);
				} elseif (! empty ( $_POST ['ctime'] [1] )) {
					// 时间小于条件
					$map ['ctime'] = array (
							'LT',
							strtotime ( $_POST ['ctime'] [1] )
					);
				}
			}
		
		}
		if (! empty ( $_POST ['title'] )) {
				$map ['title'] = array (
						'like',					
						 "%".$_POST ['title']."%" 						
				);
		}
		if (! empty ( $_POST ['profile'] )) {
			$map ['profile'] = array (
					'like',
					"%".$_POST ['profile']."%"
			);
		}
		if (! empty ( $_POST ['content'] )) {
			$map ['content'] = array (
					'like',
					"%".$_POST ['content']."%"
			);
		}
		// 查询数据
		$list = $this->where ( $map )->order ( $order )->findPage ( $limit );
		//if(isset ( $_POST )) {echo $this->getLastSql();exit;}
// 		dump($list);
// 		dump($this->getDbError());
// 		exit;
		return $list;
	
	}
}
